package cn.lf.android.lawfirm.undertake.approval;


import android.content.Intent;
import android.view.View;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import cn.lf.android.lawfirm.OrdinaryBaseActivity;
import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.undertake.approval.controler.LawyerFeeInfoController;
import cn.lf.android.lawfirm.undertake.approval.controler.LawyerFeeListConroller;
import cn.lf.android.lawfirm.undertake.approval.modle.LawyerFee;
import cn.lf.android.lawfirm.undertake.approval.modle.LawyerFeeInfo;
import cn.lf.android.lawfirm.undertake.approval.view.LawyerFeeAdapter;

import static cn.lf.android.lawfirm.R.id.eb_tv_right;
import static cn.lf.android.lawfirm.R.id.img_left;
import static cn.lf.android.lawfirm.R.id.rl_search;

public class LawyerFeeListActivity extends OrdinaryBaseActivity implements LawyerFeeListConroller.LawyerFeeCallback {
    private ListView mListView;
    private LawyerFeeAdapter mLawyerFeeAdapter;
    private List<LawyerFee> list = new ArrayList<LawyerFee>();
    private LawyerFeeListConroller mLawyerFeeListConroller;
    private String caseId = "";

    @Override
    public int getChildView() {
        return R.layout.activity_lawyerfee_list;
    }

    @Override
    public void initViewId() {
        initTitle();
        caseId = getIntent().getStringExtra("caseId");
        mListView = (ListView) findId(R.id.lv_list);
        mLawyerFeeAdapter = new LawyerFeeAdapter(this, list, 0);
        mListView.setAdapter(mLawyerFeeAdapter);
        mRL_search.setVisibility(View.GONE);
    }

    @Override
    public void refreshLoad() {

    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case eb_tv_right://保存
                Intent intent1 = new Intent(this, AddLawyerFeeActivity.class);
                intent1.putExtra("from", "");
                startActivity(intent1);
                break;
            case img_left:
                finish();
                break;
            case rl_search:
                Intent intent = new Intent(this, UndertakeSearchListActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }


    private void initTitle() {
        mImgLeft.setVisibility(View.VISIBLE);
        mImgLeft.setOnClickListener(this);
        mTitle.setVisibility(View.VISIBLE);
        mTitle.setText("律师费");
        mTvRight.setVisibility(View.GONE);
        mTvRight.setText("保存");
    }

    private LawyerFeeInfo mLawyerFeeInfo;

    @Override
    public void initData() {
        getData();
//        mLawyerFeeInfo = (LawyerFeeInfo) getIntent() .getSerializableExtra("feelist");
//        if(null!=mLawyerFeeInfo){
//            list.addAll(mLawyerFeeInfo.Payment);
//            mLawyerFeeAdapter.notifyDataSetChanged();
//        }
    }

    private void getData() {
        mLawyerFeeListConroller = new LawyerFeeListConroller(this, this);
        mLawyerFeeListConroller.onLawyerFeeist(caseId);
    }


    @Override
    public void onLawyerFeeSuccessed(List<LawyerFee> beans) {
        list.addAll(beans);
        mLawyerFeeAdapter.notifyDataSetChanged();
    }

    @Override
    public void onLawyerFeeFailed() {

    }
}
